package com.app.miwawa.api.system.entity.view;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import javax.persistence.Entity;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.framework.common.api.entity.CommonEntityUUID;

import com.app.miwawa.api.system.service.bo.AccountBo;

/**
 * 系统管理－账户
 * <p>描述: </p>
 * <p>Company: Professional</p>
 * @author chanlong(陈龙)
 * @date 2016年2月7日 下午3:44:41
 * @version 1.0.2016
 */
@Entity @Table(name = "VB_ACCOUNT")
public class Account extends CommonEntityUUID {

	/** serialVersionUID(long):. */
	private static final long serialVersionUID = 7632314510467610396L;
	
	// user
	private String sex;
	private String type;
	private String code;
	private String name;
	private String nickName;
	private String picture;
	private String post;
	private String duty;
	private String email;
	private String mobile;
	private String account;
	private String password;
	private String createDate;
	private String description;
	
	// dept
	private String deptid;
	private String dept;
	
	// shops
	private String shopsid;
	private String shops;
	
	// center
	private String centerid;
	private String center;
	private String dburl;
	private String dbname;
	
	@Transient
	private Map<String, String> params;
	
	@Transient
	private Map<Object, Boolean> auths; 
	
	public Account checkMobile(final AccountBo bo){
		return bo.checkMobile(this);
	}
	
	public Account checkPassword(final AccountBo bo){
		return bo.checkPassword(this);
	}

	public String getSex() {
		return sex;
	}

	public void setSex(String sex) {
		this.sex = sex;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public String getName() {
		return name;
	}

	public String getNickName() {
		return nickName;
	}

	public void setNickName(String nickName) {
		this.nickName = nickName;
	}

	public String getPicture() {
		return picture;
	}

	public void setPicture(String picture) {
		this.picture = picture;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getPost() {
		return post;
	}

	public void setPost(String post) {
		this.post = post;
	}

	public String getDuty() {
		return duty;
	}

	public void setDuty(String duty) {
		this.duty = duty;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getMobile() {
		return mobile;
	}

	public void setMobile(String mobile) {
		this.mobile = mobile;
	}

	public String getAccount() {
		return account;
	}

	public void setAccount(String account) {
		this.account = account;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getCreateDate() {
		return createDate;
	}

	public void setCreateDate(String createDate) {
		this.createDate = createDate;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public String getDeptid() {
		return deptid;
	}

	public void setDeptid(String deptid) {
		this.deptid = deptid;
	}

	public String getDept() {
		return dept;
	}

	public void setDept(String dept) {
		this.dept = dept;
	}

	public String getShopsid() {
		return shopsid;
	}

	public void setShopsid(String shopsid) {
		this.shopsid = shopsid;
	}

	public String getShops() {
		return shops;
	}

	public void setShops(String shops) {
		this.shops = shops;
	}

	public String getCenterid() {
		return centerid;
	}

	public void setCenterid(String centerid) {
		this.centerid = centerid;
	}

	public String getCenter() {
		return center;
	}

	public void setCenter(String center) {
		this.center = center;
	}

	public String getDburl() {
		return dburl;
	}

	public void setDburl(String dburl) {
		this.dburl = dburl;
	}

	public String getDbname() {
		return dbname;
	}

	public void setDbname(String dbname) {
		this.dbname = dbname;
	}

	public Map<String, String> getParams() {
		return params;
	}

	public void setParams(Map<String, String> params) {
		this.params = params;
	}

	public Map<Object, Boolean> getAuths() {
		return auths;
	}

	public void addAuths(final Object key, final boolean value) {
		if(this.auths == null){
			this.auths = new HashMap<Object, Boolean>();
		}
		this.auths.put(key, value);
	}
	
	public void setAuths(Map<Object, Boolean> auths) {
		this.auths = auths;
	}
	
	public void setAuths(final AccountBo bo){
		List<Map<String,Object>> auths = bo.getAuths(this.id);
		for (Map<String, Object> auth : auths) {
			Set<String> keys = auth.keySet();
			for (String key : keys) {
				if(key.equals("code")){
					addAuths(auth.get(key), true);
				}
			}
		}
	}
}
